﻿namespace MefContrib.Models.Provider.Tests
{
    using NUnit.Framework;

    [TestFixture]
    public class DefaultObjectFactoryTests
    {
        [Test]
        public void ShouldCreateInstanceOfTypeUsingDefaultConstructor()
        {
            DefaultObjectFactory factory =
                new DefaultObjectFactory();

            FakeFactoryPart instance =
                factory.Create(typeof(FakeFactoryPart)) as FakeFactoryPart;

            Assert.IsTrue(instance.GetType() == typeof(FakeFactoryPart));
        }

        [Test]
        public void ShouldCreateInstanceOfTypeUsingNullParameter()
        {
            DefaultObjectFactory factory =
                new DefaultObjectFactory();

            FakeFactoryPart instance =
                factory.Create(typeof(FakeFactoryPart), null) as FakeFactoryPart;

            Assert.IsNull(instance.Parameter);
        }

        [Test]
        public void ShouldCreateInstanceOfTypeUsingParameterValue()
        {
            DefaultObjectFactory factory =
                new DefaultObjectFactory();

            FakeFactoryPart instance =
                factory.Create(typeof(FakeFactoryPart), "dummy value") as FakeFactoryPart;

            Assert.AreEqual(instance.Parameter, "dummy value");
        }
    }

    public class FakeFactoryPart
    {
        public FakeFactoryPart()
        {
        }

        public FakeFactoryPart(string parameter)
        {
            this.Parameter = parameter;
        }

        public string Parameter { get; set; }
    }
}